<#-- 由于KE定义插件不是太方便, 用ftl方式来做稍微好点 -->
<style>
.ke-icon-quote {
	background-image: url(/static/images/quote.gif);
	width: 16px;
	height: 16px;
}
</style>

<script type="text/javascript">
	KindEditor.lang({
		quote: "引用某段文字"
	});
	
	function html_decode(str) {   
		var s = "";   
		if (str.length == 0) return "";   
		s = str.replace(/&gt;/g, "&");   
		s = s.replace(/&lt;/g, "<");   
		s = s.replace(/&gt;/g, ">");   
		s = s.replace(/&nbsp;/g, " ");   
		s = s.replace(/&#39;/g, "\'");   
		s = s.replace(/&quot;/g, "\"");   
		s = s.replace(/<br>/g, "\n");   
		return s;   
	}
	
	KindEditor.plugin("quote", function(K) {
		var editor = this, name = "quote";
		
		function insert(source) {
			var html = '<blockquote>';
			html += html_decode(source);
			html += '</blockquote><br>';
			editor.insertHtml(html);
		}
		
		// 点击图标时执行
		editor.clickToolbar(name, function() {
			var source = editor.selectedHtml();
			if (source != "") {
				var range = editor.cmd.range;
				range.deleteContents(); // 选择文字将继续保留?????
				insert(source);
			} else {
				var html = ['<div style="padding:10px 20px;">',
					'<textarea name="source" class="ke-textarea" style="width:408px;height:220px;"></textarea>',
					'</div>'].join('');
				
				var dialog = K.dialog({
					width : 450,
					title : editor.lang(name),
					body : html,
					closeBtn : {
						name : '关闭',
						click : function(e) {
							dialog.remove();
						}
					},
					yesBtn : {
						name : '确定',
						click : function(e) {
							var div = dialog.div;
							var source = K("[name='source']", div).val();
							if (source != "") {
								insert(source);
								dialog.remove();
							} else {
								alert("未输入内容");
							}
						}
					},
					noBtn : {
						name : '取消',
						click : function(e) {
							dialog.remove();
						}
					}
				});
			}
		});
	});
</script>